package com.sheng.util;

import com.sheng.application.WhyApplication;
import com.sheng.whyclass.person.model.StudentInfoData;
import com.sheng.whyclass.person.model.TeacherInfoData;

/**
 * Created by Administrator on 2016/4/4.
 */
public class LoginDataHelper {
    private static LoginDataHelper sInstance = null;
    private static StudentInfoData.DataBean loginUserInfo;
    private static TeacherInfoData.DataBean loginTeacherInfo;

    public static LoginDataHelper getInstance() {
        if (null == sInstance) {
            synchronized (LoginDataHelper.class) {
                if (null == sInstance) {
                    sInstance = new LoginDataHelper();
                }
            }
        }
        return sInstance;
    }

    public static synchronized StudentInfoData.DataBean getLoginUserInfo() {
        if (null == loginUserInfo) {
            String data = ServiceConfigManager.getInstance(
                    WhyApplication.getAppContext()).getLoginUserInfo();
            if (!TextUtils.isEmpty(data)) {
                loginUserInfo = StudentInfoData.DataBean.getFromJson(data);
            }
        }
        return loginUserInfo;
    }

    public static boolean isLogin() {
        StudentInfoData.DataBean info = getLoginUserInfo();
        if (info == null) {
            return false;
        }
        return true;
    }

    public synchronized void setLoginUserInfo(String data) {
        if (TextUtils.isEmpty(data)) {
            return;
        }
        ServiceConfigManager.getInstance(WhyApplication.getAppContext()).setLoginUserInfo(data);
        loginUserInfo = null;
        loginUserInfo = getLoginUserInfo();
    }

    public synchronized void clearLoginUserInfo() {

        ServiceConfigManager.getInstance(WhyApplication.getAppContext()).setLoginUserInfo("");
        loginUserInfo = null;
        loginUserInfo = getLoginUserInfo();
    }



    public static synchronized TeacherInfoData.DataBean getLoginTeacherInfo() {
        if (null == loginTeacherInfo) {
            String data = ServiceConfigManager.getInstance(
                    WhyApplication.getAppContext()).getLoginTeacherInfo();
            if (!TextUtils.isEmpty(data)) {
                loginTeacherInfo = TeacherInfoData.DataBean.getFromJson(data);
            }
        }
        return loginTeacherInfo;
    }

    public synchronized void setLoginTeacherInfo(String data) {
        if (TextUtils.isEmpty(data)) {
            return;
        }
        ServiceConfigManager.getInstance(WhyApplication.getAppContext()).setLoginTeacherInfo(data);
        loginTeacherInfo = null;
        loginTeacherInfo = getLoginTeacherInfo();
    }

    public synchronized void clearLoginTeacherInfo() {

        ServiceConfigManager.getInstance(WhyApplication.getAppContext()).setLoginTeacherInfo("");
        loginTeacherInfo = null;
        loginTeacherInfo = getLoginTeacherInfo();
    }




}
